package com.itheima.demo;

//智能家居控制器（设计成单例类）
public class SmartHomeController {

    //步骤1：创建一个静态的成员变量，用于存储唯一的实例
    private static final SmartHomeController smartHomeController = new SmartHomeController();

    //步骤2：私有化构造方法，防止外部创建实例
    private SmartHomeController() {
    }

    //步骤3：提供公共的静态方法，返回唯一的实例
    public static SmartHomeController getInstance() {
        return smartHomeController;
    }

    public void control(Appliance appliance) {
        System.out.println();
        System.out.println(appliance.getName() + "当前状态为：" + ((appliance.isStatus() ? "开" : "关")));
        appliance.press();   //按下开关
        System.out.println(appliance.getName() + "调整后状态为：" + ((appliance.isStatus() ? "开" : "关")));
        System.out.println();
    }

    //a.展示全部家电的情况
    public void printAll(Appliance[] appliances) {

        //使用循环遍历数组
        for (int i = 0; i < appliances.length; i++) {
            System.out.println((i + 1) + appliances[i].getName() + "当前状态为：" + ((appliances[i].isStatus() ? "开" : "关")));
        }

        System.out.println();
    }

}
